import { Canvas } from './core/Canvas';
import { Rectangle } from './shapes/Rectangle';
import { Circle } from './shapes/Circle';

document.addEventListener('DOMContentLoaded', () => {
    const canvas = new Canvas('canvas-container');

    // 添加按钮事件监听
    const drawRectBtn = document.getElementById('draw-rect');
    const drawCircleBtn = document.getElementById('draw-circle');
    const clearBtn = document.getElementById('clear');

    if (drawRectBtn) {
        drawRectBtn.addEventListener('click', () => {
            const rect = new Rectangle(
                Math.random() * 700, // x
                Math.random() * 500, // y
                100, // width
                80  // height
            );
            rect.setFillStyle(`rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`);
            canvas.addShape(rect);
        });
    }

    if (drawCircleBtn) {
        drawCircleBtn.addEventListener('click', () => {
            const circle = new Circle(
                Math.random() * 700, // x
                Math.random() * 500, // y
                40  // radius
            );
            circle.setFillStyle(`rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`);
            canvas.addShape(circle);
        });
    }

    if (clearBtn) {
        clearBtn.addEventListener('click', () => {
            canvas.clear();
        });
    }
}); 